/*
 * @Author: Simon 1958058172@qq.com
 * @Date: 2025-08-19 10:26:16
 * @LastEditors: Simon 1958058172@qq.com
 * @LastEditTime: 2025-08-19 11:15:45
 * @FilePath: \java.1212\csdn\xiancheng\li01\Test02.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package csdn.xiancheng.li01;

public class Test02 {
    //匿名内部类，重写run
    public static void main(String[] args) {
        Thread t1=new Thread("My_Thread"){
            //匿名内部类
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println("在t线程中");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            };
        };
        t1.start();
        //获取名称
        String tname=t1.getName();
        System.out.println("name:"+tname);

        t1.setName("you_Thread");
        String tname2=t1.getName();
        System.out.println("tname:"+tname2);

        for (int i = 0; i < 10; i++) {
            System.out.println("在main线程中");
        }
        //获取执行当前线程的对象
        Thread threadMain=Thread.currentThread();
        System.out.println(threadMain.getName());
        
        
    }
}
